let ul = document.querySelector("ul");
let el = "";
fetch("http://chst.vip:1234/api/getinlanddiscount")
  .then((body) => body.json())
  .then((res) => {
    console.log(res);
    res.result.forEach((item) => {
      // let regExp = /(?<=imgurl=)[^'"]*/
      let regExp = /(?<=src=)[^'"]*/;
      let url = item.productImg.match(regExp);
      // console.log(url)
      el += `<li id=${item.productId}>
    ${url.input}
    <p>${item.productName}</p>
    <span>${item.productPrice}</span>
    <span>${item.productFrom}|${item.productTime}</span>
</li>`;
    });
    ul.innerHTML = el;
  });

function setUrl() {
  // 请求首页数据
  let ul = document.querySelector("ul");
  ul.addEventListener(
    "click",
    function (e) {
      let arr = [...e.path].reverse();
      let _this = arr[5];
      let id = _this.getAttribute("id");
      // let name = $(_this).find('p').text()
      console.log(id);
      location.href = "gnzclist.html?id=" + id;
    },
    false
  );
}
setUrl();
